<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__post-wcs}">
      <wms-form v-model="dataForm" :formList="formList" :table-column="tableColumn" :advanced="advanced"
        @check-change="checkChange" @changeAdvance="changeAdvance" @getDataList="getDataList" @getReset="getReset">
        <el-form-item>
          <el-button type="primary" @click="commandResend()">{{'指令重发'}}</el-button>
        </el-form-item>
      </wms-form>
      <wms-table ref="wmsTable" v-model="dataForm" :page="page" :total="total" :limit="limit" :tableData="dataList"
        :table-column="column" :module-options="mixinViewModuleOptions" :dataListLoading="dataListLoading"
        :showSelection="true" @addOrUpdateHandle="addOrUpdateHandle"
        @selection-change="handleSelectionChange" @deleteHandle="deleteHandle"
        @pageSizeChangeHandle="pageSizeChangeHandle" @pageCurrentChangeHandle="pageCurrentChangeHandle" />
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './components/post-wcs-add-or-update'
import { formList, tableColumn } from './config'
import wmsTable from '@/components/wms-table'
import wmsForm from '@/components/wms-form'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/wms/post-wcs/page',
        getDataListIsPage: true,
        exportURL: '/wms/post-wcs/export',
        deleteURL: '/wms/post-wcs',
        deleteIsBatch: true
      },
      ids:[],
      dataForm: {
        postId: ''
      },
      formList,
      tableColumn,
      column: [],
      advanced: false
    }
  },
  components: {
    AddOrUpdate,
    wmsTable,
    wmsForm
  },
  methods: {
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
    },
  //1.任务重发
    commandResend() {
      if (!this.ids || this.ids.length != 1) {
        return this.$message({
          message: '请选择一条指令重发',
          type: "warning",
          duration: 1000,
        });
      }
      let id = this.ids[0]
      this.$confirm(
        this.$t("prompt.info", { handle: this.$t("指令重发") }),
        this.$t("prompt.title"),
        {
          confirmButtonText: this.$t("confirm"),
          cancelButtonText: this.$t("cancel"),
          type: "warning",
        }
      ).then(() => {
        console.info(id);
        this.dataForm.postId = id;
        this.$http.post("/wms/post-wcs/resend", this.dataForm)
          .then(({ data: res }) => {
            if (res.code != 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: res.data,
              type: "success",
              duration: 1000,
              onClose: () => {
                this.getDataList();
              },
            });
          })
          .catch(() => { });
      })
        .catch(() => { });
    },
  },
}
</script>
